package com.bstek.dorado_springboot;

import java.util.LinkedHashSet;
import java.util.Set;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

import com.bstek.dorado.web.loader.DoradoLoader;
import com.bstek.dorado.web.servlet.DoradoServlet;

@SpringBootApplication
public class Application  {

	@Bean
	public ServletRegistrationBean<DoradoServlet> doradoServlet() {
		ServletRegistrationBean<DoradoServlet> servlet = new ServletRegistrationBean<DoradoServlet>(new DoradoServlet());
		servlet.setLoadOnStartup(1);
		servlet.addUrlMappings("*.d");
		servlet.addUrlMappings("*.c");
		servlet.addUrlMappings("*.dpkg");
		servlet.addUrlMappings("/dorado/*");
		return servlet;
	}
	

	public static void main(String[] args) throws Exception {
		System.setProperty("doradoHome", "classpath:dorado-home/");

		SpringApplication app = new SpringApplication(Application.class);
		app.addInitializers(new DoradoApplicationContextInilializer());

		DoradoLoader doradoLoader = DoradoLoader.getInstance();
		doradoLoader.preload(true);

		Set<String> sources = new LinkedHashSet<String>();
		sources.addAll(doradoLoader.getContextLocations(false));
		app.setSources(sources);

		app.run(args);
	}
}
